

let Command = require('./command');

// 移动一个Sel
class MoveSelCommand extends  Command{
    constructor(sel,newPos){
        super();

        this.name = 'Move Sel Node';
        this.type = 'MoveSel';
        this.updatable = true;

        this.newPos = newPos;
        this.oldPos = sel.node.getPosition();

        this.setObj('sel',sel);
        this.setObj('chain',sel.getChain());
    }

    update(cmd){
        this.newPos.set(cmd.newPos);
    }

    execute(){
        let chain = this.getObj('chain');
        let sel = this.getObj('sel');
        myTools.asset(chain,'chain can not null!');
        myTools.asset(sel,'sel can not null!');
        chain.moveSel(sel,this.newPos);
    }

    undo(){
        let chain = this.getObj('chain');
        let sel = this.getObj('sel');
        myTools.asset(chain,'chain can not null!');
        myTools.asset(sel,'sel can not null!');
        chain.moveSel(sel,this.oldPos);
    }
}

module.exports = MoveSelCommand;
